package com.example.redis.demos.web.Redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-07-13
 * Time:11:18
 * Text：
 */
public class Redis_Hash {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("120.46.91.1",6379);
        try(Jedis jedis = jedisPool.getResource()){
            jedis.auth("2287448684t");
            Test3(jedis);
        }
    }
    public static  void Test1(Jedis jedis){
        System.out.println("hset  ||  hget");
        jedis.flushAll();
        jedis.hset("key1","f1","111");
        Map<String,String> fileds = new HashMap<>();
        fileds.put("f2","222");
        fileds.put("f3","333");
        fileds.put("f4","444");
        jedis.hmset("key2",fileds);

        jedis.hmget("key1","f1","f2","f3");

        System.out.println(jedis.hget("key2","f2"));

    }
    public static void Test2(Jedis jedis){
        System.out.println("---Hsexists----");
        jedis.flushAll();
        jedis.hset("key1","f1","111");
        Map<String,String> fileds = new HashMap<>();
        fileds.put("f2","222");
        fileds.put("f3","333");
        fileds.put("f4","444");
        jedis.hset("key2",fileds);

        System.out.println(jedis.hexists("key2","f2"));

        System.out.println("----hdel----");

        System.out.println(jedis.hdel("key2","f2"));
        System.out.println(jedis.hexists("key2","f2"));
    }
    public static void Test3(Jedis jedis){
        System.out.println("hkeys ||  hvals");

        jedis.flushAll();
        jedis.hset("key1","f1","111");
        jedis.hset("key1","f1","222");
        jedis.hset("key1","f1","333");

        System.out.println(jedis.hkeys("key1"));
        System.out.println(jedis.hvals("key1"));
    }

    public static  void Test4(Jedis jedis){
        System.out.println("hmget  || hmset");
        jedis.flushAll();

        Map<String,String> map= new HashMap<>();
        map.put("f1","111");

    }

}
